package com.itheima.easy.web;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.easy.feign.FaceToFacePayFeign;
import com.itheima.easy.vo.TradingVo;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付
 *
 * @Author itcast
 * @Create 2023/6/13
 **/
@RestController
@RequestMapping("/pay")
@Api(tags = "支付功能")
public class PayController {

    @Autowired
    private FaceToFacePayFeign faceToFacePayFeign;

    /**
     * 调用支付微服务实现支付功能
     * @param tradingVo
     * @return
     */
    @PostMapping("/precreate")
    @GlobalTransactional
    @ApiOperation(value = "扫码-用户扫商家",notes = "扫码-用户扫商家")
    @ApiImplicitParam(name = "tradingVo",value = "交易单",required = true,dataType = "TradingVo")
    @ApiOperationSupport(includeParameters ={"tradingVo.memo", "tradingVo.tradingAmount",
            "tradingVo.tradingChannel","tradingVo.productOrderNo", "tradingVo.enterpriseId"})
    public TradingVo precreate(@RequestBody TradingVo tradingVo){
        //通过Feign接口调用支付微服务
        tradingVo = faceToFacePayFeign.precreate(tradingVo);
        return tradingVo;
    }
}
